import Vue from 'vue'
import Vuex, { Store } from 'vuex'
import { getUserInfo } from '../api/api'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    name: '',
    token: '',
    jobAccount: '',
    role: '',
    phone: '',
    username: '',
    loaded: false,
    logined: false
  },
  getters: {
    name: state => state.name,
    token: state => state.token,
    jobAccount: state => state.jobAccount,
    role: state => state.role,
    phone: state => state.phone,
    username: state => state.username,
    // loaded: state => state.loaded,
    logined: state => state.logined
  },
  mutations: {
    loginInfo2 (state, payload) {
      state.name = payload.name
      state.jobAccount = payload.jobAccount
      state.phone = payload.phone
      state.role = payload.role
      state.username = payload.username
      state.logined = true
    },
    subLogout (state) {
      
    }
  },
  actions: {
    getMemberInfo (context) {
      return new Promise((resolve, reject) => {
        getUserInfo().then(res => {
          // console.log(res.data)
          context.commit('loginInfo2', res.data)
          resolve('返回成功')
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
})

export default store